package edu.umich.PowerTutor.phone;

import android.content.Context;
import edu.umich.PowerTutor.components.CPU.CpuData;
import edu.umich.PowerTutor.components.LCD.LcdData;
import edu.umich.PowerTutor.components.OLED.OledData;
import edu.umich.PowerTutor.components.Wifi.WifiData;

public class BravoPowerCalculator extends DreamPowerCalculator {
	public BravoPowerCalculator(Context context) {
		super(new BravoConstants(context));
	}

	public BravoPowerCalculator(PhoneConstants coeffs) {
		super(coeffs);
	}

	@Override
	public double getOledPower(OledData data) {

		if (!data.screenOn) {
			return 0;
		}
		if (data.pixPower == -1) {
			return coeffs.oledBasePower() + coeffs.lcdBrightness()
					* data.brightness;
		} else {
			// 원래 이곳을 통해서 픽셀 파워가 결정 되어야 한다. 하지만 난 bright로만 power 소비를 결정 한다.
			return coeffs.oledBasePower() + coeffs.lcdBrightness()
					* data.brightness;
			// return coeffs.oledBasePower() + data.pixPower * data.brightness;
		}
		
	}

	// HTC Desire LCD Power Model
	@Override
	public double getLcdPower(LcdData data) {
		/*
		 * return data.screenOn ? coeffs.lcdBrightness() * data.brightness +
		 * coeffs.lcdBacklight() : 0;
		 */
		return data.screenOn ? coeffs.lcdBrightness() * data.brightness
				+ coeffs.lcdBacklight() : 0;
	}

	// HTC Desire wifi power model 이다.
	@Override
	public double getWifiPower(WifiData data) {
		if (!data.wifiOn) {
			return 0;
		} else {
			// 과도한 오차를 막기위해서 upper bound를 둔다.
			double wifiPower = Math.max(0,23.764+
	    			data.packets*2.231+
	    			data.packets*data.packets*0.053);
			if (wifiPower >= 890.704) {
				return 890.704;
			} else {
				return wifiPower;
			}
		}
	}
	// HTC Desire cpu power model 이다.
	@Override
	public double getCpuPower(CpuData data) {
		// HTC Desire cpu power model 이다.
		return Math.max(0, 7.080 * (data.usrPerc + data.sysPerc) + 131.495);
	}
}
